//
//  User.swift
//  WeiBoSwift
//
//  Created by Jacky Sun on 16/5/11.
//  Copyright © 2016年 syf. All rights reserved.
//

import UIKit

class User: NSObject {

     /// 用户ID
    var id: Int = 0
    
    var name: String?
    /// 用户头像地址（中图），50×50像素
    var profile_image_url: String?{
        didSet{
            if let img = profile_image_url {
                userIcon = NSURL(string: img)
            }
        }
    }
     /// 用户头像
    var  userIcon: NSURL?
    
    
    /// 时候是认证, true是, false不是
    var verified: Bool = false
    
    /// 用户的认证类型，-1：没有认证，0，认证用户，2,3,5: 企业认证，220: 达人
    var verified_type: Int = -1 {
        didSet{
            switch verified_type {
            case 0:
                verifiedIMg =  UIImage(named: "avatar_vip")
            case 2, 3, 5:
            verifiedIMg = UIImage(named: "avatar_enterprise_vip")
            case 220:
                verifiedIMg = UIImage(named: "avatar_grassroot")
            default:
            verifiedIMg = nil
                
            }
            
        }
    }
    // 用户认证图片
    var verifiedIMg: UIImage?
    
    /// 会员等级
    // 基本数据类型初始化时要赋值，否则不会分配内存空间
    var mbrank: Int = 0
        {
        didSet{
            if mbrank > 0 && mbrank < 7
            {
                mbrankImage = UIImage(named: "common_icon_membership_level\(mbrank)")
            }
        }
    }
    var mbrankImage: UIImage?

    
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    
    
    override var description: String{
        let property = ["id", "name", "profile_image_url", "verified", "verified_type"]
        let  dict = dictionaryWithValuesForKeys(property)
        return "\(dict)"
    }
}
